home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / util / misc / Fudgit233.lha / Source / src / alloc.c next >
Encoding:
C/C++ Source or Header  |  1993-12-14  |  1.5 KB  |  90 lines

  1. #include <ctype.h>
  2. #ifndef NOMALLOC_H
  3. #include <malloc.h>
  4. #endif
  5.  
  6. #ifndef NULL
  7. #define NULL 0
  8. #endif
  9.  
  10. int *Ft_ivector(int nl, int nh)
  11. {
  12.     int *v;
  13.  
  14.     v=(int *)calloc((unsigned) (nh-nl+1), sizeof(int));
  15.     if (v == (int *)NULL) {
  16.         return(NULL);
  17.     }
  18.     else {
  19.         return(v-nl);
  20.     }
  21. }
  22.  
  23. double *Ft_dvector(int nl, int nh)
  24. {
  25.     double *v;
  26.  
  27.     v=(double *)calloc((unsigned) (nh-nl+1), sizeof(double));
  28.     if (v == (double *)NULL) {
  29.         return(NULL);
  30.     }
  31.     else {
  32.         return(v-nl);
  33.     }
  34. }
  35.  
  36. double **Ft_dmatrix(int nrl, int nrh, int ncl, int nch)
  37. {
  38.     int i;
  39.     double **m;
  40.  
  41.     m=(double **) calloc((unsigned) (nrh-nrl+1), sizeof(double*));
  42.     if (m == (double **)NULL) {
  43.         return(NULL);
  44.     }
  45.     m -= nrl;
  46.  
  47.     for(i=nrl;i<=nrh;i++) {
  48.         m[i]=(double *) calloc((unsigned) (nch-ncl+1), sizeof(double));
  49.         if (m[i] == (double *)NULL) {
  50.             while (i>=nrl) {
  51.                 free(m[i]);
  52.                 i--;
  53.             }
  54.             free(m);
  55.             return(NULL);
  56.         }
  57.         m[i] -= ncl;
  58.     }
  59.     return(m);
  60. }
  61.  
  62. void Ft_free_ivector(int *v, int nl, int nh)
  63. {
  64.     if (v != 0) {
  65.         free((char*) (v+nl));
  66.     }
  67.     return;
  68. }
  69.  
  70. void Ft_free_dvector(double *v, int nl, int nh)
  71. {
  72.     if (v != 0) {
  73.         free((char*) (v+nl));
  74.     }
  75.     return;
  76. }
  77.  
  78. void Ft_free_dmatrix(double **m, int nrl, int nrh, int ncl, int nch)
  79. {
  80.     int i;
  81.  
  82.     if (m != 0) {
  83.         for(i=nrh;i>=nrl;i--) {
  84.             free((char*) (m[i]+ncl));
  85.         }
  86.         free((char*) (m+nrl));
  87.     }
  88.     return;
  89. }
  90.